Skip to content

discoveryengine: add pre-delete hook to detach stores on destroy#17273

Open
btkelly wants to merge 4 commits intoGoogleCloudPlatform:mainfrom
btkelly:fix-data-connector-deletion
Open

discoveryengine: add pre-delete hook to detach stores on destroy#17273
btkelly wants to merge 4 commits intoGoogleCloudPlatform:mainfrom
btkelly:fix-data-connector-deletion

Conversation

@btkelly
Copy link
Copy Markdown
Member

@btkelly btkelly commented Apr 23, 2026

This PR updates the google_discovery_engine_data_connector resource to use the standard Google provider pattern for deletion behavior by introducing the deletion_policy field.

It adds a custom pre_delete hook that detaches associated Data Stores from Search Engines before deleting the Data Connector when deletion_policy = "FORCE", preventing circular dependency/destruction order errors and leaving the resource clean.

An acceptance test was added (TestAccDiscoveryEngineDataConnector_deletionPolicyForce) using the Jira data source (avoiding the complex IdP setup requirements needed for ServiceNow).

Release Note Template for Downstream PRs (will be copied)

See Write release notes for guidance.

discoveryengine: added `deletion_policy` field to `google_discovery_engine_data_connector` resource to handle destruction order dependencies.

@modular-magician modular-magician added the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label Apr 23, 2026
@github-actions github-actions Bot requested a review from melinath April 23, 2026 21:27
@github-actions
Copy link
Copy Markdown

Googlers: For automatic test runs see go/terraform-auto-test-runs.

@melinath, a repository maintainer, has been assigned to review your changes. If you have not received review feedback within 2 business days, please leave a comment on this PR asking them to take a look.

You can help make sure that review is quick by doing a self-review and by running impacted tests locally.

@modular-magician modular-magician added service/discoveryengine and removed awaiting-approval Pull requests that need reviewer's approval to run presubmit tests labels Apr 23, 2026
@modular-magician
Copy link
Copy Markdown
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

google provider: Diff ( 4 files changed, 253 insertions(+))
google-beta provider: Diff ( 4 files changed, 253 insertions(+))

@modular-magician
Copy link
Copy Markdown
Collaborator

Non-exercised tests

🔴 Tests were added that are skipped in VCR:

  • TestAccDiscoveryEngineDataConnector_detachStoresOnDestroy

Tests analytics

Total tests: 41
Passed tests: 35
Skipped tests: 5
Affected tests: 1

Click here to see the affected service packages
  • discoveryengine

Action taken

Found 1 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
  • TestAccDiscoveryEngineDataStore_discoveryengineDatastoreKmsKeyNameExample

Get to know how VCR tests work

@modular-magician
Copy link
Copy Markdown
Collaborator

🔴 Tests failed during RECORDING mode:
TestAccDiscoveryEngineDataStore_discoveryengineDatastoreKmsKeyNameExample [Error message] [Debug log]

🔴 Errors occurred during RECORDING mode. Please fix them to complete your PR.

View the build log or the debug log for each test

collection_id: 'collection-id'

virtual_fields:
- name: 'detach_stores_on_destroy'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it could be a good candidate for a deletion_policy field that has a FORCE option (which would trigger detaching stores). What would you think about that? Some more information on deletion policy fields at https://googlecloudplatform.github.io/magic-modules/best-practices/deletion-behaviors/ (though it's a bit sparse... basically it's a virtual field like you have, but it takes an enum rather than a bool.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for me, I'd rather follow existing patterns. This was a pattern inside the Dialog Flow modules but it looks like a one off. I'll update this to be an enum with "DEFAULT" which does nothing additional and "FORCE" to detach the stores.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the pattern to follow the deletion policy format, take a look when you get a second and let me know if that works for you.

@modular-magician modular-magician added the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label Apr 30, 2026
@github-actions github-actions Bot requested a review from melinath April 30, 2026 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-approval Pull requests that need reviewer's approval to run presubmit tests service/discoveryengine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants